import axios from 'axios'

const api = axios.create({
  baseURL: '/api',
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json'
  }
})

// 请求拦截器
api.interceptors.request.use(
  config => {
    // 可以在这里添加认证token等
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

// 响应拦截器
api.interceptors.response.use(
  response => {
    return response
  },
  error => {
    console.error('API请求错误:', error)
    return Promise.reject(error)
  }
)

export default {
  // 员工管理
  getEmployees() {
    return api.get('/employees')
  },
  getEmployeeById(id) {
    return api.get(`/employees/${id}`)
  },
  createEmployee(employee) {
    return api.post('/employees', employee)
  },
  updateEmployee(id, employee) {
    return api.put(`/employees/${id}`, employee)
  },
  deleteEmployee(id) {
    return api.delete(`/employees/${id}`)
  },
  searchEmployees(name) {
    return api.get(`/employees/search?name=${name}`)
  },

  // 培训记录
  getTrainings() {
    return api.get('/trainings')
  },
  getTrainingById(id) {
    return api.get(`/trainings/${id}`)
  },
  getTrainingsByEmployeeId(employeeId) {
    return api.get(`/trainings/employee/${employeeId}`)
  },
  getTrainingRecordByName(name) {
    return api.get(`/trainings/getTrainingRecordByName/${name}`)
  },
  createTraining(training) {
    return api.post('/trainings', training)
  },
  updateTraining(id, training) {
    return api.put(`/trainings/${id}`, training)
  },
  deleteTraining(id) {
    return api.delete(`/trainings/${id}`)
  },

  // 绩效数据
  getPerformances() {
    return api.get('/performances')
  },
  getPerformanceById(id) {
    return api.get(`/performances/${id}`)
  },
  getPerformancesByEmployeeId(employeeId) {
    return api.get(`/performances/employee/${employeeId}`)
  },
  getPerformanceRecordByName(name) {
    return api.get(`/performances/getPerformancesByEmployeeId/${name}`)
  },
  createPerformance(performance) {
    return api.post('/performances', performance)
  },
  updatePerformance(id, performance) {
    return api.put(`/performances/${id}`, performance)
  },
  deletePerformance(id) {
    return api.delete(`/performances/${id}`)
  },

  // 岗位要求
  getPositions() {
    return api.get('/positions')
  },
  getPositionById(id) {
    return api.get(`/positions/${id}`)
  },
  getPositionByName(positionName) {
    return api.get(`/positions/name/${positionName}`)
  },
  createPosition(position) {
    return api.post('/positions', position)
  },
  updatePosition(id, position) {
    return api.put(`/positions/${id}`, position)
  },
  deletePosition(id) {
    return api.delete(`/positions/${id}`)
  },

  // 评估服务
  getComprehensiveAssessment(request) {
    return api.post('/assessment/comprehensive', request)
  },
  getEmployeeData(employeeId) {
    return api.get(`/assessment/employee/${employeeId}/data`)
  }
}